/**
 * Created by wenchuan.li 2018/4/27.
 */
define(["public/app.min"],function () {

    var self, app = win.app, user;

    var reg = app.Module.extend({

        init: function () {
            self = this;

            self.data = {
               username: '',
                password: ''
            };
            self._super({
                _tag: 'register_p'
            }, win);

        },
        subData: function () {
            var _data = self.data.sub;
            if (!_data.GWAA002 || _data.GWAA002 == '') {
                app.toast('姓名不能为空');
                return;
            }
            if (!_data.GWAA005 || _data.GWAA005 == '') {
                app.toast('出生日期不能为空');
                return;
            }
            if (!_data.GWAA004 || _data.GWAA004 == '') {
                app.toast('手机号不能为空');
                return;
            }
            _data.GWAA001 = user.id;
            app.ajax({
                xurl: "api/wx/user/registerUser",
                loading: true,
                xdata: _data,
                cb: function (result) {
                    if (result.ok) {
                        app.alert({
                            msg: '注册成功！',
                            ok: function () {
                                app.back(1);
                            }
                        });
                    } else {
                        app.alert({
                            msg: result.data.appmsg,
                            ok: function () {
                                app.back(1);
                            }
                        });
                    }
                }
            });
        },
        _lazy: function () { // 延迟300ms加载
            app.taps.call(win, [{
                o: 'submitDiv',
                cb: function (e) {
                    self.subData();
                }
            }]);
            mui('.mui-scroll-wrapper').scroll({
                deceleration: 0.0005
            });
        },
        _ready: function () { // dom载入完成后执行
            new Vue({
                el: doc.querySelector('.mui-content'),
                data: self.data,
                methods: {
                    login: function () {
                        app.ajax({
                            xurl: "api/wx/user/checkAccount",
                            loading: true,
                            xdata: {username: self.data.username,password: self.data.password},
                            cb: function (result) {
                                console.log(result.data)
                                if(result.data.code == 200){
                                    app.openPage({
                                        src: "main.html"
                                    });
                                }else{
                                    app.toast(result.data.message);
                                }
                            }
                        });
                    },
                    register: function () {
                        app.openPage({
                            src: "register/register.html"
                        });
                    }
                }
            });
        }
    });

    new reg();

});